namespace DotNetNuke.Entities.Modules
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Security;
    using DotNetNuke.Security.Permissions;
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;
    using System.Xml.Serialization;

    [XmlRoot("module", IsNullable=false)]
    public class ModuleInfo
    {
        private string _Alignment = Null.NullString;
        private bool _AllModules;
        private bool _AllTabs;
        private string _AuthorizedEditRoles = Null.NullString;
        private string _AuthorizedRoles;
        private string _AuthorizedViewRoles = Null.NullString;
        private string _Border = Null.NullString;
        private string _BusinessControllerClass;
        private int _CacheTime;
        private string _Color = Null.NullString;
        private string _ContainerPath;
        private string _ContainerSrc = Null.NullString;
        private string _ControlSrc;
        private string _ControlTitle;
        private SecurityAccessLevel _ControlType;
        private string _Description;
        private int _DesktopModuleID;
        private bool _DisplayPrint = true;
        private bool _DisplaySyndicate = false;
        private bool _DisplayTitle = true;
        private DateTime _EndDate = Null.NullDate;
        private string _Footer = Null.NullString;
        private string _FriendlyName;
        private string _Header = Null.NullString;
        private string _HelpUrl;
        private string _IconFile = Null.NullString;
        private bool _InheritViewPermissions;
        private bool _IsAdmin;
        private bool _IsDefaultModule;
        private bool _IsDeleted;
        private bool _IsPremium;
        private int _ModuleControlId;
        private int _ModuleDefID = Null.NullInteger;
        private int _ModuleID = Null.NullInteger;
        private int _ModuleOrder;
        private ModulePermissionCollection _ModulePermissions;
        private string _ModuleTitle = Null.NullString;
        private int _PaneModuleCount;
        private int _PaneModuleIndex;
        private string _PaneName;
        private int _PortalID = Null.NullInteger;
        private DateTime _StartDate = Null.NullDate;
        private int _SupportedFeatures;
        private int _TabID = Null.NullInteger;
        private int _TabModuleID = Null.NullInteger;
        private string _Version;
        private VisibilityState _Visibility;

        public ModuleInfo Clone()
        {
            ModuleInfo objModuleInfo = new ModuleInfo();
            objModuleInfo.PortalID = this.PortalID;
            objModuleInfo.TabID = this.TabID;
            objModuleInfo.TabModuleID = this.TabModuleID;
            objModuleInfo.ModuleID = this.ModuleID;
            objModuleInfo.ModuleDefID = this.ModuleDefID;
            objModuleInfo.ModuleOrder = this.ModuleOrder;
            objModuleInfo.PaneName = this.PaneName;
            objModuleInfo.ModuleTitle = this.ModuleTitle;
            objModuleInfo.AuthorizedEditRoles = this.AuthorizedEditRoles;
            objModuleInfo.CacheTime = this.CacheTime;
            objModuleInfo.AuthorizedViewRoles = this.AuthorizedViewRoles;
            objModuleInfo.Alignment = this.Alignment;
            objModuleInfo.Color = this.Color;
            objModuleInfo.Border = this.Border;
            objModuleInfo.IconFile = this.IconFile;
            objModuleInfo.AllTabs = this.AllTabs;
            objModuleInfo.Visibility = this.Visibility;
            objModuleInfo.AuthorizedRoles = this.AuthorizedRoles;
            objModuleInfo.IsDeleted = this.IsDeleted;
            objModuleInfo.Header = this.Header;
            objModuleInfo.Footer = this.Footer;
            objModuleInfo.StartDate = this.StartDate;
            objModuleInfo.EndDate = this.EndDate;
            objModuleInfo.ContainerSrc = this.ContainerSrc;
            objModuleInfo.DisplayTitle = this.DisplayTitle;
            objModuleInfo.DisplayPrint = this.DisplayPrint;
            objModuleInfo.DisplaySyndicate = this.DisplaySyndicate;
            objModuleInfo.InheritViewPermissions = this.InheritViewPermissions;
            objModuleInfo.DesktopModuleID = this.DesktopModuleID;
            objModuleInfo.FriendlyName = this.FriendlyName;
            objModuleInfo.Description = this.Description;
            objModuleInfo.Version = this.Version;
            objModuleInfo.IsAdmin = this.IsAdmin;
            objModuleInfo.IsPremium = this.IsPremium;
            objModuleInfo.SupportedFeatures = this.SupportedFeatures;
            objModuleInfo.BusinessControllerClass = this.BusinessControllerClass;
            objModuleInfo.ModuleControlId = this.ModuleControlId;
            objModuleInfo.ControlSrc = this.ControlSrc;
            objModuleInfo.ControlType = this.ControlType;
            objModuleInfo.ControlTitle = this.ControlTitle;
            objModuleInfo.HelpUrl = this.HelpUrl;
            objModuleInfo.ContainerPath = this.ContainerPath;
            objModuleInfo.PaneModuleIndex = this.PaneModuleIndex;
            objModuleInfo.PaneModuleCount = this.PaneModuleCount;
            objModuleInfo.IsDefaultModule = this.IsDefaultModule;
            objModuleInfo.AllModules = this.AllModules;
            objModuleInfo.ModulePermissions = this.ModulePermissions;
            return objModuleInfo;
        }

        private bool GetFeature(DesktopModuleSupportedFeature Feature)
        {
            bool isSet = false;
            if ((this.SupportedFeatures & (int)Feature) == (int)Feature)
            {
                isSet = true;
            }
            return isSet;
        }

        public void Initialize(int PortalId)
        {
            this._PortalID = PortalId;
            this._TabID = -1;
            this._ModuleID = -1;
            this._ModuleDefID = -1;
            this._ModuleOrder = -1;
            this._PaneName = "";
            this._ModuleTitle = "";
            this._AuthorizedEditRoles = "";
            this._CacheTime = -1;
            this._AuthorizedViewRoles = "";
            this._Alignment = "";
            this._Color = "";
            this._Border = "";
            this._IconFile = "";
            this._AllTabs = false;
            this._Visibility = VisibilityState.Maximized;
            this._IsDeleted = false;
            this._Header = "";
            this._Footer = "";
            this._StartDate = Null.NullDate;
            this._EndDate = Null.NullDate;
            this._DisplayTitle = true;
            this._DisplayPrint = true;
            this._DisplaySyndicate = false;
            this._InheritViewPermissions = false;
            this._ContainerSrc = "";
            this._DesktopModuleID = -1;
            this._FriendlyName = "";
            this._Description = "";
            this._Version = "";
            this._IsPremium = false;
            this._IsAdmin = false;
            this._SupportedFeatures = 0;
            this._BusinessControllerClass = "";
            this._ModuleControlId = -1;
            this._ControlSrc = "";
            this._ControlType = SecurityAccessLevel.Anonymous;
            this._ControlTitle = "";
            this._HelpUrl = "";
            this._ContainerPath = "";
            this._PaneModuleIndex = 0;
            this._PaneModuleCount = 0;
            this._IsDefaultModule = false;
            this._AllModules = false;
            Hashtable settings = PortalSettings.GetSiteSettings(PortalId);
            if ((Convert.ToString(RuntimeHelpers.GetObjectValue(settings["defaultmoduleid"])) != "") & (Convert.ToString(RuntimeHelpers.GetObjectValue(settings["defaulttabid"])) != ""))
            {
                ModuleInfo objModule = new ModuleController().GetModule(int.Parse(Convert.ToString(RuntimeHelpers.GetObjectValue(settings["defaultmoduleid"]))), int.Parse(Convert.ToString(RuntimeHelpers.GetObjectValue(settings["defaulttabid"]))));
                if (objModule != null)
                {
                    this._CacheTime = objModule.CacheTime;
                    this._Alignment = objModule.Alignment;
                    this._Color = objModule.Color;
                    this._Border = objModule.Border;
                    this._IconFile = objModule.IconFile;
                    this._Visibility = objModule.Visibility;
                    this._ContainerSrc = objModule.ContainerSrc;
                    this._DisplayTitle = objModule.DisplayTitle;
                    this._DisplayPrint = objModule.DisplayPrint;
                    this._DisplaySyndicate = objModule.DisplaySyndicate;
                }
            }
        }

        [XmlElement("alignment")]
        public string Alignment
        {
            get
            {
                return this._Alignment;
            }
            set
            {
                this._Alignment = value;
            }
        }

        [XmlIgnore]
        public bool AllModules
        {
            get
            {
                return this._AllModules;
            }
            set
            {
                this._AllModules = value;
            }
        }

        [XmlElement("alltabs")]
        public bool AllTabs
        {
            get
            {
                return this._AllTabs;
            }
            set
            {
                this._AllTabs = value;
            }
        }

        [XmlIgnore]
        public string AuthorizedEditRoles
        {
            get
            {
                return this._AuthorizedEditRoles;
            }
            set
            {
                this._AuthorizedEditRoles = value;
            }
        }

        [XmlIgnore]
        public string AuthorizedRoles
        {
            get
            {
                return this._AuthorizedRoles;
            }
            set
            {
                this._AuthorizedRoles = value;
            }
        }

        [XmlIgnore]
        public string AuthorizedViewRoles
        {
            get
            {
                return this._AuthorizedViewRoles;
            }
            set
            {
                this._AuthorizedViewRoles = value;
            }
        }

        [XmlElement("border")]
        public string Border
        {
            get
            {
                return this._Border;
            }
            set
            {
                this._Border = value;
            }
        }

        [XmlIgnore]
        public string BusinessControllerClass
        {
            get
            {
                return this._BusinessControllerClass;
            }
            set
            {
                this._BusinessControllerClass = value;
            }
        }

        [XmlElement("cachetime")]
        public int CacheTime
        {
            get
            {
                return this._CacheTime;
            }
            set
            {
                this._CacheTime = value;
            }
        }

        [XmlElement("color")]
        public string Color
        {
            get
            {
                return this._Color;
            }
            set
            {
                this._Color = value;
            }
        }

        [XmlIgnore]
        public string ContainerPath
        {
            get
            {
                return this._ContainerPath;
            }
            set
            {
                this._ContainerPath = value;
            }
        }

        [XmlElement("containersrc")]
        public string ContainerSrc
        {
            get
            {
                return this._ContainerSrc;
            }
            set
            {
                this._ContainerSrc = value;
            }
        }

        [XmlIgnore]
        public string ControlSrc
        {
            get
            {
                return this._ControlSrc;
            }
            set
            {
                this._ControlSrc = value;
            }
        }

        [XmlIgnore]
        public string ControlTitle
        {
            get
            {
                return this._ControlTitle;
            }
            set
            {
                this._ControlTitle = value;
            }
        }

        [XmlIgnore]
        public SecurityAccessLevel ControlType
        {
            get
            {
                return this._ControlType;
            }
            set
            {
                this._ControlType = value;
            }
        }

        [XmlIgnore]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                this._Description = value;
            }
        }

        [XmlIgnore]
        public int DesktopModuleID
        {
            get
            {
                return this._DesktopModuleID;
            }
            set
            {
                this._DesktopModuleID = value;
            }
        }

        [XmlElement("displayprint")]
        public bool DisplayPrint
        {
            get
            {
                return this._DisplayPrint;
            }
            set
            {
                this._DisplayPrint = value;
            }
        }

        [XmlElement("displaysyndicate")]
        public bool DisplaySyndicate
        {
            get
            {
                return this._DisplaySyndicate;
            }
            set
            {
                this._DisplaySyndicate = value;
            }
        }

        [XmlElement("displaytitle")]
        public bool DisplayTitle
        {
            get
            {
                return this._DisplayTitle;
            }
            set
            {
                this._DisplayTitle = value;
            }
        }

        [XmlElement("enddate")]
        public DateTime EndDate
        {
            get
            {
                return this._EndDate;
            }
            set
            {
                this._EndDate = value;
            }
        }

        [XmlElement("footer")]
        public string Footer
        {
            get
            {
                return this._Footer;
            }
            set
            {
                this._Footer = value;
            }
        }

        [XmlIgnore]
        public string FriendlyName
        {
            get
            {
                return this._FriendlyName;
            }
            set
            {
                this._FriendlyName = value;
            }
        }

        [XmlElement("header")]
        public string Header
        {
            get
            {
                return this._Header;
            }
            set
            {
                this._Header = value;
            }
        }

        [XmlIgnore]
        public string HelpUrl
        {
            get
            {
                return this._HelpUrl;
            }
            set
            {
                this._HelpUrl = value;
            }
        }

        [XmlElement("iconfile")]
        public string IconFile
        {
            get
            {
                return this._IconFile;
            }
            set
            {
                this._IconFile = value;
            }
        }

        [XmlElement("inheritviewpermissions")]
        public bool InheritViewPermissions
        {
            get
            {
                return this._InheritViewPermissions;
            }
            set
            {
                this._InheritViewPermissions = value;
            }
        }

        [XmlIgnore]
        public bool IsAdmin
        {
            get
            {
                return this._IsAdmin;
            }
            set
            {
                this._IsAdmin = value;
            }
        }

        [XmlIgnore]
        public bool IsDefaultModule
        {
            get
            {
                return this._IsDefaultModule;
            }
            set
            {
                this._IsDefaultModule = value;
            }
        }

        [XmlIgnore]
        public bool IsDeleted
        {
            get
            {
                return this._IsDeleted;
            }
            set
            {
                this._IsDeleted = value;
            }
        }

        [XmlIgnore]
        public bool IsPortable
        {
            get
            {
                return this.GetFeature(DesktopModuleSupportedFeature.IsPortable);
            }
        }

        [XmlIgnore]
        public bool IsPremium
        {
            get
            {
                return this._IsPremium;
            }
            set
            {
                this._IsPremium = value;
            }
        }

        [XmlIgnore]
        public bool IsSearchable
        {
            get
            {
                return this.GetFeature(DesktopModuleSupportedFeature.IsSearchable);
            }
        }

        [XmlIgnore]
        public int ModuleControlId
        {
            get
            {
                return this._ModuleControlId;
            }
            set
            {
                this._ModuleControlId = value;
            }
        }

        [XmlIgnore]
        public int ModuleDefID
        {
            get
            {
                return this._ModuleDefID;
            }
            set
            {
                this._ModuleDefID = value;
            }
        }

        [XmlElement("moduleID")]
        public int ModuleID
        {
            get
            {
                return this._ModuleID;
            }
            set
            {
                this._ModuleID = value;
            }
        }

        [XmlIgnore]
        public int ModuleOrder
        {
            get
            {
                return this._ModuleOrder;
            }
            set
            {
                this._ModuleOrder = value;
            }
        }

        [XmlArrayItem("permission"), XmlArray("modulepermissions")]
        public ModulePermissionCollection ModulePermissions
        {
            get
            {
                return this._ModulePermissions;
            }
            set
            {
                this._ModulePermissions = value;
            }
        }

        [XmlElement("title")]
        public string ModuleTitle
        {
            get
            {
                return this._ModuleTitle;
            }
            set
            {
                this._ModuleTitle = value;
            }
        }

        [XmlIgnore]
        public int PaneModuleCount
        {
            get
            {
                return this._PaneModuleCount;
            }
            set
            {
                this._PaneModuleCount = value;
            }
        }

        [XmlIgnore]
        public int PaneModuleIndex
        {
            get
            {
                return this._PaneModuleIndex;
            }
            set
            {
                this._PaneModuleIndex = value;
            }
        }

        [XmlIgnore]
        public string PaneName
        {
            get
            {
                return this._PaneName;
            }
            set
            {
                this._PaneName = value;
            }
        }

        [XmlIgnore]
        public int PortalID
        {
            get
            {
                return this._PortalID;
            }
            set
            {
                this._PortalID = value;
            }
        }

        [XmlElement("startdate")]
        public DateTime StartDate
        {
            get
            {
                return this._StartDate;
            }
            set
            {
                this._StartDate = value;
            }
        }

        [XmlIgnore]
        public int SupportedFeatures
        {
            get
            {
                return this._SupportedFeatures;
            }
            set
            {
                this._SupportedFeatures = value;
            }
        }

        [XmlIgnore]
        public int TabID
        {
            get
            {
                return this._TabID;
            }
            set
            {
                this._TabID = value;
            }
        }

        [XmlIgnore]
        public int TabModuleID
        {
            get
            {
                return this._TabModuleID;
            }
            set
            {
                this._TabModuleID = value;
            }
        }

        [XmlIgnore]
        public string Version
        {
            get
            {
                return this._Version;
            }
            set
            {
                this._Version = value;
            }
        }

        [XmlElement("visibility")]
        public VisibilityState Visibility
        {
            get
            {
                return this._Visibility;
            }
            set
            {
                this._Visibility = value;
            }
        }
    }
}

